Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Implement /_matrix/client/v1/rooms/{roomId}/threads (I am being lazy so can someone finish off this for me?) #3404

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

qwqtoday
Copy link

@qwqtoday qwqtoday commented Jul 31, 2024

Signed-off-by: Leung Ho Ching <lukas.leung@hotmail.com>

Pull Request Checklist

@qwqtoday qwqtoday requested a review from a team as a code owner July 31, 2024 05:56
@qwqtoday qwqtoday marked this pull request as draft July 31, 2024 06:00
@qwqtoday qwqtoday closed this Jul 31, 2024
@qwqtoday qwqtoday reopened this Aug 9, 2024
@qwqtoday qwqtoday marked this pull request as ready for review August 9, 2024 07:33
@qwqtoday
Copy link
Author

qwqtoday commented Aug 9, 2024

this pr doesn't need tests because it's obviously working

@notramo
Copy link

notramo commented Aug 14, 2024

It needs tests so when new features are added or refactored, it won't break, and other devs who submit different pull requests, don't have to test this feature each time they submit a new PR. Tests are for future stability, the current feature is obviously always working, because if it wouldn't work, the dev would spend more time on it. But when 10 other features are added, nobody wants to manually test this feature 10 times to avoid breaking it while implementing those new features.

@qwqtoday
Copy link
Author

It needs tests so when new features are added or refactored, it won't break, and other devs who submit different pull requests, don't have to test this feature each time they submit a new PR. Tests are for future stability, the current feature is obviously always working, because if it wouldn't work, the dev would spend more time on it. But when 10 other features are added, nobody wants to manually test this feature 10 times to avoid breaking it while implementing those new features.

Sure I will do it later

@qwqtoday
Copy link
Author

@S7evinK can you run the workflow to test it?

Copy link
Contributor

@S7evinK S7evinK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad for a start!
A few things to check, though. Feel free to ask in #dendrite-dev if you have questions.

syncapi/storage/tables/interface.go Outdated Show resolved Hide resolved
tab, _, close := newRelationsTable(t, dbType)
defer close()

err = tab.InsertRelation(ctx, nil, room.ID, firstEvent.EventID(), threadReplyEvent.EventID(), "m.room.message", threadReplyEvent.EventID())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the input is wrong:

InsertRelation(ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, childEventType, relType string) (err error)

t.Fatal(err)
}
var eventIds []string
eventIds, _, err = tab.SelectThreads(ctx, nil, room.ID, "", 0, 100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error check.

t.Fatalf("eventID mismatch: got %s, want %s", eventID, expected)
}
}
eventIds, _, err = tab.SelectThreads(ctx, nil, room.ID, alice.ID, 0, 100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, missing error check.


var userID string
if include == "participated" {
_, err := spec.NewUserID(device.UserID, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, err := spec.NewUserID(device.UserID, true)
_, err = spec.NewUserID(device.UserID, true)

}

for _, event := range headeredEvents {
ce, err := synctypes.ToClientEvent(event, synctypes.FormatAll, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the roomID is not needed, as we're already requesting for a specific room?

Suggested change
ce, err := synctypes.ToClientEvent(event, synctypes.FormatAll, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
ce, err := synctypes.ToClientEvent(event, synctypes.FormatSync, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {

@@ -811,3 +811,39 @@ func (d *DatabaseTransaction) RelationsFor(ctx context.Context, roomID, eventID,

return events, prevBatch, nextBatch, nil
}

func (d *DatabaseTransaction) ThreadsFor(ctx context.Context, roomID, userID string, from types.StreamPosition, limit uint64) (
events []*rstypes.HeaderedEvent, prevBatch, nextBatch string, err error,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevBatch is always empty, so can be removed.

Comment on lines +209 to +220
room := test.NewRoom(t, alice)

firstEvent := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{
"body": "first message",
})
threadReplyEvent := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{
"body": "thread reply",
"m.relates_to": map[string]interface{}{
"event_id": firstEvent.EventID(),
"rel_type": threadRelType,
},
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an in-memory room, so when you query the relation below, there won't be any events in the database. This means you'll also need to create a newOutputRoomEventsTable(t, dbType) below, like you did with the relations table. Then insert the events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be formatted.

Co-authored-by: Till <2353100+S7evinK@users.noreply.github.com>
@qwqtoday qwqtoday changed the title Implement /_matrix/client/v1/rooms/{roomId}/threads Implement /_matrix/client/v1/rooms/{roomId}/threads (I am being lazy so can someone finish off this for me?) Nov 4, 2024
@S7evinK
Copy link
Contributor

S7evinK commented Nov 14, 2024

Thanks for contributing to Dendrite!

The repo has been cloned into element-hq/dendrite and made the switch to AGPL as per https://matrix.org/blog/2023/11/06/future-of-synapse-dendrite/.
For more information, feel free to read this and this

If you still wish to contribute under the new license, feel free to create a new PR over at element-hq/dendrite.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants